
<template>
  <div class="app-container">
    <div class="filter-container">
      <filter-form :i-org-options="options" />
      <!-- <el-button type="danger">删除</el-button> -->
    </div>
    <el-table v-loading="loading" :data="tableData" style="width: 100%" border>
      <el-table-column type="index" label="序号" width="55" align="center" />
      <el-table-column prop="strDevicename" label="设备名称" width="180" />
      <el-table-column prop="strValue" label="设备类型" width="80" />
      <el-table-column prop="strDevicenum" label="设备序列号" />
      <el-table-column prop="strGrantdevicenum" label="设备码" width="80" />
      <el-table-column prop="strOrgname" label="所属机构" width="140" />
      <el-table-column prop="strValue1" label="设备状态" width="140" />
      <el-table-column label="操作" width="180">
        <template slot-scope="{row,$index}">
          <router-link
            :to="{
              path:'publishAdd',
              query:{
                iOrgsysnum:row.iOrgsysnum,
                iDevicesysnum:row.iDevicesysnum,
                strDevicename:row.strDevicename,
                strOrgname: row.strOrgname,
                iDevicetype: row.iDevicetype,
                strValue: row.strValue,
                strGrantdevicenum: row.strGrantdevicenum
              }
            }"
          >
            <el-button size="mini" type="primary">发布</el-button>
          </router-link>
          <el-button size="mini" type="danger" @click="handleDelete(row,$index)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <Pagination
      v-show="total>0"
      :total="total"
      :page.sync="pagenum"
      :limit.sync="limit"
      :layout="layout"
      @pagination="fetchList"
    />
  </div>
</template>
<script>
import { deleteDeviceInfo } from '@/api/addTag'
import Pagination from '@/components/Pagination'
import FilterForm from './componts/filterForm'
import { getOrglist } from '@/api/addTag'
import { mqsend, beforeList } from '@/api/devices/index'
import { mapGetters } from 'vuex'

export default {
  name: 'PublishlList',
  components: { Pagination, FilterForm },

  props: {},
  data() {
    return {
      total: 0,
      limit: 5,
      pagenum: 1,
      currentpage: 1,
      options: [],
      layout: 'total, prev, pager, next, jumper',
      form: {
        strDevicename: '',
        iDevicetype: '',
        iOrgsysnum: ''
      },
      loading: false,
      tableData: []
    }
  },
  computed: {
    ...mapGetters(['iOrgsysnum'])
  },
  created() {
    this.fetchList()
    getOrglist().then(res => {
      // console.log(res)
      this.options = res.data
    })
  },

  mounted() {},
  methods: {
    handleModifyStatus(row, status) {
      this.$message({
        message: '操作成功',
        type: 'success'
      })
      this.dialogPvVisible = true
      this.form = row
    },
    handleDelete(row, index) {
      this.$confirm('确认删除吗？', 'Warning', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          deleteDeviceInfo({ iDevicesysnum: row.iDevicesysnum }).then(res => {
            // console.log(res);
            this.$message({
              title: 'Success',
              message: '删除成功',
              type: 'success',
              duration: 2000
            })
            this.fetchList()
          })
        })
        .catch(err => {
          console.error(err)
        })
    },
    fetchList() {
      mqsend({ pagenum: this.pagenum, type: 2, iOrgsysnums: this.iOrgsysnum }).then(res => {
        console.log(res)
      }).catch(err => {
        console.log(err)
      })
      this.loading = true

      setTimeout(() => {
        // type 类型（1，所有设备，2，）
        beforeList({ pagenum: this.pagenum, type: 2, iOrgsysnums: this.iOrgsysnum }).then(res => {
          this.tableData = res.data
          this.total = res.total
          this.currentpage = res.currentpage
          this.loading = false
        })
      }, 3000)
    }
  }
}
</script>

<style lang="scss" scoped>
.marginTop {
  margin-top: 20px;
}
.title {
  margin: 30px 0;
}
</style>
